package com.jwdf.uda.view.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;

import com.jwdf.uda.R;
import com.jwdf.uda.databinding.DialogTplAlertBinding;
import com.jwdf.uda.utils.ConfigUtils;


/**
 * Created by Administrator on 2016/11/30.
 */

public class TPLAlertDialog extends BaseDialog {
    private DialogTplAlertBinding mDataBinding;
    private boolean mCancelable = true;
    private TPLAlertDialog.CallbackListener mListener;

    public interface CallbackListener {
        void clickYes();
    }

    public TPLAlertDialog(Context context) {
        this(context,null);
    }

    public TPLAlertDialog(Context context, TPLAlertDialog.CallbackListener listener) {
        super(context);
        setCancelable(false);
        this.mListener = listener;
    }

    public void setCallbackListener(TPLAlertDialog.CallbackListener listener) {
        this.mListener = listener;
    }

    public void setCanBackDismiss(boolean canBackDismiss) {
        this.mCancelable = canBackDismiss;
    }

    @Override
    protected View onInflateView(LayoutInflater inflater) {
        mDataBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_tpl_alert, null, false);
        return mDataBinding.getRoot();
    }

    @Override
    protected void onInitView(View view) {
        mDataBinding.flSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mListener != null) mListener.clickYes();
            }
        });
        mDataBinding.chkRemind.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ConfigUtils.setNoTPLRemind(buttonView.getContext(),isChecked);
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (mCancelable) {
            super.onBackPressed();
        }
    }
}
